package com.rayson.yututu.model.vo;

import cn.hutool.json.JSONUtil;
import com.rayson.yututu.model.entity.Picture;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;

/**
 * Author: rayson
 * Description:
 * Version: 1.0
 * Date: 2024-12-24 22:23
 */
@Data
public class PictureVO implements Serializable {
    private static final long serialVersionUID = -5340829273554165324L;

    private String id;

    private String url;

    private String name;

    private String introduction;

    private List<String> tags;

    private String category;

    private Long picSize;

    private Integer picWidth;

    private Integer picHeight;

    private Double picScale;

    private String picFormat;

    private String userId;
    /**
     * 所属空间id
     */
    private String spaceId;

    /**
     * 编辑时间
     */
    private Date editTime;

    /**
     * 创建时间
     */
    private Date createTime;

    /**
     * 更新时间
     */
    private Date updateTime;

    private UserVO userVO;

    /**
     * 权限列表
     */
    private List<String> permissionList = new ArrayList<>();


    public static Picture toPicture(PictureVO pictureVO) {
        Picture picture = new Picture();
        BeanUtils.copyProperties(pictureVO, picture);
        picture.setTags(JSONUtil.toJsonStr(pictureVO.getTags()));
        return picture;
    }

    public static PictureVO toPictureVO(Picture picture) {
        if (Objects.isNull(picture)) {
            return null;
        }
        PictureVO pictureVO = new PictureVO();
        BeanUtils.copyProperties(picture, pictureVO);
        pictureVO.setTags(JSONUtil.toList(picture.getTags(), String.class));
        return pictureVO;
    }
}
